layui.use(['form'], function () {
    var form = layui.form,
        layer = layui.layer;

    // 粒子线条背景
    $(document).ready(function(){
        $('.layui-container').particleground({
            dotColor:'#5cbdaa',
            lineColor:'#5cbdaa'
        });
    });

    // 进行登录操作
    form.on('submit(login)', function (data) {
        data = data.field;
        globalObj.login(data);
        return false;
        /*if (data.username == '') {
            layer.msg('用户名不能为空');
            return false;
        }
        if (data.password == '') {
            layer.msg('密码不能为空');
            return false;
        }
        if (data.captcha == '') {
            layer.msg('验证码不能为空');
            return false;
        }*/
    });

});

var globalObj = globalObj || {};
globalObj = $.extend(globalObj, {
    login: function (data) {
        (new globalObj.Request(globalObj.url)).setParams({
            param: {
                username: data.username,
                password: data.password
            },
            serviceId: "app.sysUser.login",
        }).do().success(function (data) {
            // session 保存
            sessionStorage.setItem('user', JSON.stringify(data.user));
            sessionStorage.setItem('sessionId', data.sessionId);
            window.location = baseUrl;
            // layer.msg('登录成功');
        });
    }
});
